package com.hzdesk.media.koreabatchmatvector.dialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.inter.StrokesChangeClick;


/**
 * Created by Administrator on 2018/4/25.
 */

public class StrokesPopWindow extends PopupWindow implements View.OnClickListener{
    private View contentView;
    private ImageView imageView_strokes_1,imageView_strokes_2,imageView_strokes_3,imageView_strokes_4;
    private StrokesChangeClick strokesChangeClick;
    private Activity context;
    public void setStrokesChangeClickListener(StrokesChangeClick strokesChangeClick1){this.strokesChangeClick=strokesChangeClick1;}

    public StrokesPopWindow(Activity context) {
        super(context);
        this.context=context;
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        contentView=inflater.inflate(R.layout.popup_strock,null);
        imageView_strokes_1=(ImageView)contentView.findViewById(R.id.strokes_1);
        imageView_strokes_2=(ImageView)contentView.findViewById(R.id.strokes_2);
        imageView_strokes_3=(ImageView)contentView.findViewById(R.id.strokes_3);
        imageView_strokes_4=(ImageView)contentView.findViewById(R.id.strokes_4);
        imageView_strokes_1.setOnClickListener(this);
        imageView_strokes_2.setOnClickListener(this);
        imageView_strokes_3.setOnClickListener(this);
        imageView_strokes_4.setOnClickListener(this);
        int h = context.getWindowManager().getDefaultDisplay().getHeight();
        int w = context.getWindowManager().getDefaultDisplay().getWidth();
        // 设置SelectPicPopupWindow的View
        this.setContentView(contentView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        // this.setWidth(h/5);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0000000000);
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        this.setBackgroundDrawable(dw);
        // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
        // 设置SelectPicPopupWindow弹出窗体动画效果
        //this.setAnimationStyle(R.style.AnimationPreview);
    }
    public void showPopupWindow(LinearLayout linearLayout){
        if (!this.isShowing()) {
            this.showAsDropDown(linearLayout, linearLayout.getLayoutParams().width / 2, 18);
            //imageView.setImageBitmap(BitmapFactory.decodeResource(contentView.getResources(),R.drawable.main_strokes_s));
        } else {
            //imageView.setImageBitmap(BitmapFactory.decodeResource(contentView.getResources(),R.drawable.main_strokes));
            this.dismiss();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.strokes_1:
                strokesChangeClick.click(1);
                break;
            case R.id.strokes_2:
                strokesChangeClick.click(2);
                break;
            case R.id.strokes_3:
                strokesChangeClick.click(3);
                break;
            case R.id.strokes_4:
                strokesChangeClick.click(4);
                break;
        }

    }
}
